<%@page import="com.teach.entity.User" %>
<%@page import="java.util.List"%>
<%@page language="java"  pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<title>表格操作</title>
		<meta charset="utf-8">
		<base href="<%=request.getContextPath()%>/"/>
		<link href="asset/css/bootstrap.min.css" rel="stylesheet"  type="text/css" />
		<script src="asset/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="asset/js/popper.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="asset/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<form class="form-inline" action="admin/selectLike-user.let">
	        <div class="form-group mx-sm-1 mb-2">
	          <label class="sr-only">新闻类别：</label>
	          <select class="form-control">
	            <option value="">全部</option>
	          </select>
	        </div>
	        <div class="form-group mx-sm-1 mb-2">
	          <label class="sr-only">关键字：</label>
	          <input type="text" class="form-control " placeholder="搜索关键字" name="search" value=""/> <!-- 给输入框加一个name属性，传给servlet -->
	        </div>
	        <button type="submit" class="btn btn-primary mb-2 " >搜索</button>
	        <a href="admin/user-add-form.jsp" class="btn btn-success ml-auto mr-2">添加</a>
	        <div class="form-group mx-sm-1 mb-2">
	          <label class="sr-only">数量：</label>
	          <select id="numSelect" class="form-control">
	          	<option value="">显示条数</option>
	            <option value="5" >每页5条</option>
	            <option value="10">每页10条</option>
	            <option value="20">每页20条</option>
	            <option value="50">每页50条</option>
	          </select>
	        </div>
	      </form>
	      
		<table class="table table-hover table-dark">
		  <thead>
		    <tr>
		      <th scope="col">#</th>
		      <th scope="col">姓名</th>
		      <th scope="col">年龄</th>
		      <th scope="col">生日</th>
		      <th scope="col">性别</th>
		      <th scope="col">操作</th>
		    </tr>
		  </thead>
		  <tbody>
		  <%
			  List<User> list1 = (List<User>)request.getAttribute("list1");
		     /*  System.out.println(list); */
			  for(int i = 0 ; i < list1.size() ; i++) {
				  User vo = list1.get(i);
			  %>
			    <tr>
			      <th scope="row"><%=i+1 %></th>
			      <td><%= vo.getLlq_name() %></td>
			      <td><%= vo.getLlq_age() %></td>
			      <td><%= vo.getLlq_birthday() %></td>
			      <td><%= vo.getLlq_sex() %></td>
				  <td class="p-1">
				  <div class="dropdown">
				  <button class="btn btn-outline-primary btn-block dropdown-toggle" type="button" data-toggle="dropdown">
				    操作
				  </button>
				  <div class="dropdown-menu dropdown-menu-right">
				    <a class="dropdown-item"  href="admin/message.let?userId=<%= vo.getLlq_id() %>">查看</a>
				    <a class="dropdown-item"  href="admin/user-update-form.let?id=<%= vo.getLlq_id() %>">修改</a>
				    <%-- <a class="dropdown-item" href="admin/tabl.let?userId=<%=vo.getLlq_id()%>">删除</a>
				    <a class="dropdown-item" onclick="return confirm('您确定要删除这条记录吗?');"  href="admin/user-delete.let?userId=<%=vo.getUserId()%>">删除</a> --%>
				    <a class="dropdown-item _delete" onclick="return confirm('您确定要删除这条记录吗?');" href="admin/delete-user.let?userId=<%= vo.getLlq_id() %>">删除</a>
				  </div>
				</div>
				</td>
			</tr>
			<%} %>
		  </tbody>
		</table>
		
		<%  int rowMax = 5;
			int total = (int)request.getAttribute("total");
			int pageMax = (total-1)/rowMax+1;
			String url = "admin/list1.let?current=";
			int current = 1;
			try {
				current = Integer.valueOf(request.getParameter("current"));
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
		%>
		<ul class="pagination justify-content-center">
			<li class="page-item"><a class="page-link" href=<%=url+1+"" %>><span aria-hidden="true">&laquo;</span></a></li>
			<% for(int i = 1; i <= pageMax; i++) {%>
			<li class="page-item <%=current==i ? "active":"" %>" ><a class="page-link" href=<%=url+i+"" %>><%=i %></a></li>
			<%} %>
			<li class="page-item"><a class="page-link" href=<%=url+pageMax+"" %>><span aria-hidden="true">&raquo;</span></a></li>
		</ul>
		
		<script>
		var numSelect = document.getElementById("numSelect");
		numSelect.onchange = function(){
			window.location="admin/display-user.let?num="+this.value;
		}
		</script>
	</body>
</html>
